/*dom操作工具类如果有jquery 优先采用jquery 否则使用dom api:此种方式同时支持vue jquery等各类框架*/
function McUtils(){
    this.$ = null;
    if(typeof jQuery !='undefined'){
        this.$ = jQuery;
    }
    if(typeof layui !='undefined'){
        this.$ = layui.jquery;
    }
    if(typeof $ !='undefined'){
        this.$ = $;
    }
}
McUtils.prototype={
    /*根据样式名获取结构*/
    getElementsByClassName:function ( className) {
        if(this.$){
            return this.$("."+className);
        }
        if (document.getElementsByClassName) {
            // 使用现有方法
            return document.getElementsByClassName(className);
        } else {
            // 循环遍历所有标签，返回带有相应类名的元素
            var results = [],
                elems = document.getElementsByTagName("*");
            for (var i = 0, len = elems.length; i < len; i++) {
                if (elems[i].className.indexOf(className) != -1) {
                    results[results.length] = elems[i];
                }
            }
            return results;
        }
    },
    /*设置结构内html*/
    html:function(node,html){
        if(this.$){
            this.$(node).html(html);
            return;
        }
        node.innerHTML = html;
    },
    /*设置css*/
    css:function(node,styleName,styleValue){
        if(this.$){
            this.$(node).css(styleName,styleValue);
            return;
        }
        node.style[styleName] = styleValue;
    },
    attr:function(node,attrName,attrValue){
        if(this.$){
            if(typeof attrValue !='undefined'){
                this.$(node).attr(attrName,attrValue);
            }else{
                return this.$(node).attr(attrName);
            }
        }else{
            if(typeof attrValue!='undefined'){
                node.setAttribute(attrName,attrValue);
            }else{
                var attrs = node.attributes;
                for (var i = 0; i < attrs.length; i++) {
                    if(attrs[i].name===attrName){
                        return attrs[i].value;
                    }
                }
                return null;
            }
        }
    }
}